#!/usr/bin/env python3
import pickle
import json

def load_result_pkl(result_path):
    """加载result.pkl文件"""
    with open(result_path, 'rb') as f:
        results = pickle.load(f)
    return results

# 加载数据
results = load_result_pkl('/disk2/xd/project/mmdetection/work_dirs/visual/result.pkl')

print("检查第一个预测结果的边界框格式:")
if len(results) > 0:
    first_result = results[0]
    if 'pred_instances' in first_result:
        pred_inst = first_result['pred_instances']
        
        print(f"pred_instances键: {list(pred_inst.keys())}")
        
        if 'bboxes' in pred_inst:
            bboxes = pred_inst['bboxes']
            print(f"bboxes类型: {type(bboxes)}")
            print(f"bboxes形状: {bboxes.shape if hasattr(bboxes, 'shape') else len(bboxes)}")
            
            if len(bboxes) > 0:
                print(f"第一个bbox: {bboxes[0]}")
                print(f"第一个bbox类型: {type(bboxes[0])}")
                print(f"第一个bbox长度: {len(bboxes[0])}")
                
                # 检查边界框格式
                if hasattr(bboxes[0], '__len__'):
                    print(f"边界框格式: [x1, y1, x2, y2] 或 [x, y, w, h]")
                    print(f"值: {bboxes[0]}")
                else:
                    print(f"边界框是单个值: {bboxes[0]}")
        
        if 'labels' in pred_inst:
            labels = pred_inst['labels']
            print(f"labels类型: {type(labels)}")
            print(f"labels形状: {labels.shape if hasattr(labels, 'shape') else len(labels)}")
            if len(labels) > 0:
                print(f"前5个labels: {labels[:5]}")
        
        if 'scores' in pred_inst:
            scores = pred_inst['scores']
            print(f"scores类型: {type(scores)}")
            print(f"scores形状: {scores.shape if hasattr(scores, 'shape') else len(scores)}")
            if len(scores) > 0:
                print(f"前5个scores: {scores[:5]}") 